package com.ruoyi.iot.service.impl;


import com.ruoyi.iot.mapper.DbMapper;
import com.ruoyi.iot.service.DbService;
import com.ruoyi.iot.util.SqlUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@AllArgsConstructor
@Service
public class DbServiceImpl implements DbService {
    @Autowired(required = false)
    private DbMapper dbMapper;

    @Override
    public int existTable(String newTableName) {
        return dbMapper.existTable(newTableName);
    }

    /**
     * 创建数据表
     *
     * @param sql 建表语句
     * @return
     */
    @Override
    public int createTable(String sql) {
        return dbMapper.createTable(sql);
    }

    @Override
    public int update(String sql) {
        return dbMapper.createTable(sql);
    }

    @Override
    public Integer count(String sql) {
        return dbMapper.count(sql);
    }

    @Override
    public int saveTable(String tablename, HashMap<String, Object> hashMap) {
        String sql= SqlUtils.buildInsertSql(tablename,hashMap);
        return dbMapper.saveTable(sql);
    }

    @Override
    public List<Map<String, Object>> getList(String sql) {
       return dbMapper.getList(sql);
    }
}
